home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / utility / passw204.zip / ENCRYPT.C < prev    next >
C/C++ Source or Header  |  1995-11-13  |  5KB  |  113 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* Module Name: encrypt.c       version: 1.00,          Date: 11/12/95      */
  4. /*                                                                          */
  5. /* Designer(s): Joe Gruessing                                               */
  6. /*                                                                          */
  7. /* Description: This program determines the encrypted form of the password  */
  8. /*              entered by the user. This password is the exclusive-OR of   */
  9. /*              each character with its corresponding position in the       */
  10. /*              string -- starting with 1 (not 0).                          */
  11. /*                                                                          */
  12. /* Returns:     0 if successful,                                            */
  13. /*              1 if failed or user aborted                                 */
  14. /*                                                                          */
  15. /****************************************************************************/
  16. /************** Copyright (C) 1995, Joseph A. Gruessing Jr. *****************/
  17. /****************************************************************************/
  18. /*                                                                          */
  19. /* HISTORY:                                                                 */
  20. /*                                                                          */
  21. /* 08/05/95     JAG     - Display encrypted password only.                  */
  22. /* 11/12/95     JAG     - Initial release completed.                        */
  23. /*                                                                          */
  24. /****************************************************************************/
  25.  
  26. #include <conio.h>
  27. #include <ctype.h>                                             /* toupper() */
  28. #include <stdio.h>                                                             
  29. #include <stdlib.h>
  30. #include <string.h>                        
  31.  
  32. #define PASSWFILE       "PASSWORD.SYS"      /* name of password driver file */
  33. #define PASSLENGTH      8                   /* length of embedded password  */
  34. #define PASSSTART       18                  /* start location of password   */                               
  35.  
  36. int main(void)
  37. {
  38.   FILE *outf;
  39.  
  40.   unsigned char inputString[PASSLENGTH + 1];
  41.               
  42.   int   i, forever;
  43.  
  44.   for (;;)              
  45.   {
  46.         clrscr();
  47.         printf("┌─────────────────────────────────────────────────┐\r\n");
  48.         printf("│ Modify Password: \"%s\" driver utility. │\r\n", PASSWFILE);
  49.         printf("│ Copyright (c) 1995 Joseph A. Gruessing Jr.      │\r\n");
  50.         printf("└─────────────────────────────────────────────────┘\r\n\r\n");
  51.         printf("Enter password  to encrypt: ");
  52.         gets(inputString);
  53.  
  54.         for (i = strlen(inputString); i < PASSLENGTH; i++)
  55.           inputString[i] = 0;
  56.  
  57.         for (i=0; i < strlen(inputString); i++)
  58.           inputString[i] = toupper(inputString[i])^(i+1);
  59.        
  60.         printf("Encrypted version to embed: %s\r\n\r\n", inputString);
  61.         printf("Selected password OK? (YyNnQq): ");
  62.  
  63.         forever = 1;
  64.  
  65.         while (forever)              /* loop #2 - wait for valid user input */
  66.         {        
  67.            i = getch();
  68.  
  69.            switch (i)
  70.            {
  71.              case 'Y':
  72.              case 'y':
  73.              {
  74.                 printf("%c\r\n\r\n%s: ", i, PASSWFILE);
  75.                 if((outf = fopen(PASSWFILE, "r+b")) == 0)
  76.                 {
  77.                    printf("Cannot open file. Aborting...\r\n\r\n");
  78.                    return(1);
  79.                 }
  80.  
  81.                 fseek(outf, PASSSTART, SEEK_SET);
  82.                 fputc(strlen(inputString), outf);
  83.                 fwrite(&inputString, PASSLENGTH, 1, outf);
  84.                 fclose(outf);
  85.                 printf("Password change complete.\r\n");
  86.                 return(0);
  87.              }
  88.  
  89.              case 'N':
  90.              case 'n':
  91.              {
  92.                 forever = 0;
  93.                 break;
  94.              }
  95.  
  96.              case 'Q':
  97.              case 'q':
  98.              {
  99.                 printf("%c\r\n\r\nNo modifications were made to \"%s\".\r\n",
  100.                        i, PASSWFILE);
  101.  
  102.                 return(1);
  103.              }
  104.  
  105.            } /* end - switch */
  106.  
  107.         } /* end - while (forever) */
  108.  
  109.   } /* end - for (;;) */
  110.  
  111. }
  112.  
  113.